<?php


namespace app\openapi\controller;


use app\common\validate\RequestCheckValidate;
use think\facade\Db;

class Login extends OpenApi
{
    protected $noNeedLogin = '*';

    /**
     * 获取token
     * @Author zengxin(573908667@qq.com)
     */
    public function get_token()
    {
        checkParam(new RequestCheckValidate(), 'login');
        $appid        = input('appid');
        $secret       = input('secret');
        $check_appid  = app()->env->get('applet_app_id');
        $check_secret = app()->env->get('applet_app_secret');

        if (empty($check_appid) || $appid != $check_appid) err_return('appid无效');
        if (empty($check_secret) || $secret != $check_secret) err_return('秘钥无效');

        $token = strtoupper(md5(uniqid()));

        $redis = redis_instance();
        $redis->set("{$this->redis_key}:openapi:{$token}", 1, 7200);

        suc_return(['token' => $token]);
    }
}